﻿/* 自定义的nebula的通用热键模块,需要指定暂停,即使存档读档,所以需要新建实例才能使用
  By setycyas @2023-01-31
*/
class MyNebula {

  ;静态常量,指定nebula的exe名称
  static EXE := "nebula.exe"
  
  ;实例变量
  _pauseKey := "" ;暂停热键
  _stateSaveKey := "" ;即时存档热键
  _stateLoadKey := "" ;即时读档热键

  __New(pauseKey := "numpad0", stateSaveKey := "delete", stateLoadKey := "PGDN"){
    local wTitle := "ahk_exe " . MyNebula.EXE ;窗口标题
    local funPause, funStateSave, funStateLoad ;绑定用函数对象,必须如此,而不能直接在绑定热键时一串表达式
    this._pauseKey := pauseKey ;暂停热键
    this._stateSaveKey := stateSaveKey ;即时存档热键
    this._stateLoadKey := stateLoadKey ;即时读档热键
    ;绑定热键
    funPause := this._pauseToggle.bind(this)
    funStateSave := this._stateSave.bind(this)
    funStateLoad := this._stateLoad.bind(this)
    Hotkey, IfWinActive, %wTitle%
    Hotkey, ~%pauseKey%, % funPause
    Hotkey, ~%stateSaveKey%, % funStateSave
    Hotkey, ~%stateLoadKey%, % funStateLoad
    Hotkey, IfWinActive
  }

  /* 私有函数,用于绑定各个按键的响应 
  */
  
  _pauseToggle(){
    send {pause down}
    sleep, 50
    send, {pause up}
  }
  _stateSave(){
    send, {F10 down}
    sleep, 50
    send, {F10 up}
  }
  _stateLoad(){
    send, {F11 down}
    sleep, 50
    send, {F11 up}
  }

}

/* 测试 
new MyNebula()
*/
